import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/net/api.dart';
import 'package:s_mankey/config/net/smonkey_ui_api.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/custom_button.dart';

class ChangePassword extends StatefulWidget {

  ChangePassword({Key key}) : super(key: key);

  @override
  _ChangePassword createState() {
    return _ChangePassword();
  }
}

class _ChangePassword extends State<ChangePassword> {

  TextEditingController _unameController;
  String errorTip;

  @override
  void initState() {
    _unameController = new TextEditingController();
    super.initState();

  }

  @override
  void dispose() {
    super.dispose();
  }

  //验证密码
  verifyPasw({@required String pasw})  {
    ResponseData res;

    ///TODO: 这里还没有完成
    try{
      SmonkeysRepository.fetchConfirmPasw(options: {'password': pasw})
          .then((value) => {

//        print('type##${value.runtimeType}'),
//        print('type###${value}'),

      }
      );
    } catch (e){
      print('我错啦$e');
    }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: AppBar(
      elevation: 1,
      title:  Text('修改密码'),),body: Form(
//      key: _formKey, //设置globalKey，用于后面获取FormState
      autovalidate: true, //开启自动校验
      child: Center(
        child: Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.only(top: 50),
              width: 250,
              child: TextFormField(
                  obscureText: true,
                  autofocus: true,
                  controller: _unameController,
                  decoration: InputDecoration(
//                    labelText: "手机号码",
                    hintText: "输入旧密码",
                    errorText: errorTip,
                    hintStyle: TextStyle(fontSize: AppFontSize.Size14),
                  ),
                  // 校验用户名
                  validator: (v) {
                    return v
                        .trim()
                        .length > 0 ? null : "密码不能为空";
                  }

              ),
            ),

            /// 点击绑定
            GestureDetector(onTap: (){
//              Navigator.pushNamed(context, RouterName.newPasword);
              print('点击登录了');
              String newText = _unameController.text;
              verifyPasw(pasw: newText);
              print(newText);
//                //验证通过提交数据
            },child:  CustomButton(
                margin: EdgeInsets.only(top: 30),
                padding: EdgeInsets.fromLTRB(0, 5, 0, 5),
                widgt: 250.0,
                title: '确认',
                fontSize: AppFontSize.Size16,
                fontColor: Colors.white,
                radius: 30.0,
                borderColor: Colors.transparent,
                gradient:AppColor.gradientColorHigh),),

            Padding(
              padding: const EdgeInsets.only(top: 10),
              child: GestureDetector(onTap: (){
//              Navigator.pushNamed(context, RouterName.newPasword);
                print('点击忘记密码了');
//                //验证通过提交数据
              },child: Text('忘记密码',style: TextStyle(fontSize: AppFontSize.Size14),),),
            ),
          ],
        ),
      ),
    ),
    );
  }
}

